package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Paymentmode;
import com.restaurant.service.PaymentmodeService;

public class PaymentmodeServiceImpl implements PaymentmodeService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Paymentmode addOrModify( Paymentmode objPaymentmode ) {
       return ( Paymentmode ) hibernateTemplate.merge( objPaymentmode );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Paymentmode deleteRecord( Paymentmode objPaymentmode ) {
       hibernateTemplate.delete( objPaymentmode );
       return objPaymentmode;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Paymentmode modifyRecord( Paymentmode objPaymentmode ) {
       return ( Paymentmode ) hibernateTemplate.merge( objPaymentmode );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Paymentmode> loadAll() {
       return (List<Paymentmode>)hibernateTemplate.findByNamedQuery( "Paymentmode.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Paymentmode loadByPrimaryKey( Long primaryKey ) {
       return (Paymentmode) hibernateTemplate.get( Paymentmode.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Paymentmode deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Paymentmode> loadByHql(String query) {
       return ( List<Paymentmode> ) hibernateTemplate.find( query );
   }
}